﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Qiang.Styles
{
    public class SimplePolygonStyle : PolygonStyle, ISimplePolygonStyle
    {

        #region 初始化

        /// <summary>
        /// 
        /// </summary>
        public SimplePolygonStyle()
        {
            _fillColor = Color.FromArgb(255, Random.Next(0, 255), Random.Next(0, 255), Random.Next(0, 255));
        }

        public SimplePolygonStyle(Color fillColor)
        {
            _fillColor = fillColor;
        }

        #endregion


        #region 属性

        Color _fillColor;

        /// <summary>
        /// 添充色。
        /// </summary>
        public Color FillColor
        {
            get { return _fillColor; }
            set { _fillColor = value; }
        }


        /// <summary>
        /// 样式类型。
        /// </summary>
        public override PolygonStyleType StyleType
        {
            get { return PolygonStyleType.Simple; }
        }

        /// <summary>
        /// 透明度。
        /// </summary>
        public override float Opacity
        {
            get
            {
                return _fillColor.A / 255f;
            }
            set
            {
                float val = value;
                if (val > 1) val = 1f;
                if (val < 0) val = 0f;
                _fillColor = Color.FromArgb((int)val * 255, _fillColor);
            }
        }


        #endregion


        #region 方法

        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="path"></param>
        public override void FillPath(Graphics g, System.Drawing.Drawing2D.GraphicsPath path)
        {
            Brush brush = ToBrush();
            g.FillPath(brush, path);
            brush.Dispose();
        }

        public override void FillRegion(Graphics g, Region region)
        {
            Brush brush = ToBrush();
            g.FillRegion(brush, region);
            brush.Dispose();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override Brush ToBrush()
        {
            SolidBrush brush = new SolidBrush(_fillColor);
            return brush;
        }




        #endregion


    }
}
